package com.base.BaseAction;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.user.bean.BBSUser;

/** 
 * ����: BaseAction</br> 
 * ����com.base.BaseAction </br> 
 * ����: </br>
 * �����汾�ţ�</br>
 * ������Ա�� ���Ʋ�</br>
 * ����ʱ�䣺 2016-4-17 
 */

public class BaseAction extends ActionSupport implements Action{
	/**
	 * pagesize  公共的页数大小，默认为 10
	 */
	public final static Integer pagesize = 10;
	/** 当前登录的用户  */
	private static final String LOGIN_USER = "user";
	
	private static final long serialVersionUID = 3511724273376447365L;

	/**
	 * ������: getSession</br>
	 * ����: ��ȡsession</br>
	 * ������Ա�����Ʋ�</br>
	 * ����ʱ�䣺2016-4-17</br>
	 * @return
	 */
	public Map<String,Object> getSession(){
		return ActionContext.getContext().getSession();
	}
	/**
	 * ������: getRequest</br>
	 * ����: ��ȡRequest</br>
	 * ������Ա�����Ʋ�</br>
	 * ����ʱ�䣺2016-4-17</br>
	 * @return
	 */
	protected HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	/**
	 * ������: getResponse</br>
	 * ����: ��ȡResponse</br>
	 * ������Ա�����Ʋ�</br>
	 * ����ʱ�䣺2016-4-17</br>
	 * @return
	 */
	protected HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}
	
	/**
	 * ���JSON�ַ�ҳ��
	 * @param json
	 * @return
	 */
	public String writeJSON(String json){
		try{
			this.getResponse().setContentType("text/html");
			this.getResponse().setCharacterEncoding("utf-8");
			this.getResponse().getWriter().println(json);
			this.getResponse().getWriter().flush();
			this.getResponse().getWriter().close();
		}catch(Exception e) {
			System.err.println(e.getMessage());
		}
		return null;
	}
	/**
	 * 方法名: getLoginUser</br>
	 * 详述: 获取当前登录的用户</br>
	 * 开发人员：汪浩博</br>
	 * 创建时间：2016-4-28</br>
	 * @return
	 */
	public BBSUser getLoginUser(){
		BBSUser user = null;
		user = (BBSUser) ServletActionContext.getRequest().getSession().getAttribute(LOGIN_USER);
		return user;
	}
}
